#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;
class Edge
{
    public:
    int to;
    int w;
    Edge *next;
    void set(int to,int w)
    {
        this->to=to;
        this->w=w;
    }
};

class Graph
{
    static const int MVN=1010,MARCN=MVN*100;
    public:
    int vn,arcn;
    Edge *edge,*head[MVN];
    int ep;
    Graph()
    {
        init(0);
        edge=new Edge[MARCN];
    };
    void init(int n)
    {
        vn=n;
        arcn=ep=0;
        fill(head,head+MVN,(Edge*)NULL);
    }
    void addEdge(int vs,int vt)
    {
        edge[ep].set(vt,ep);
        edge[ep].next=head[vs];
        head[vs]=&edge[ep++];
        arcn++;
    }
};

class Tarjan
{
    static const int MVN=1010;
    public:
    int order[MVN],low[MVN],cnt;
    Graph g;
    int res[MVN];
    void init(Graph &g)
    {
        delete(&g);
        this->g=g;
    }
    void dfs(int pos)
    {
        order[pos]=low[pos]=cnt++;
        for(Edge *e=g.head[pos];e;e=e->next)
        {
            if(order[e->to]==-1)
            {
                dfs(e->to);
                if(low[e->to]<low[pos]) low[pos]=low[e->to];
                else if(low[e->to]>=order[pos])res[pos]++;
            }
            else if(order[e->to]<low[pos]) low[pos]=order[e->to];
        }
    }
    void go()
    {
        fill(order,order+g.vn,-1);
        fill(res,res+g.vn,0);
        cnt = 0;
        for(int i=0;i<g.vn;i++) if(order[i]==-1&&g.head[i]!=NULL)
            dfs(i);
    }
    void printRes()
    {
        bool empty = true;
        for(int i=0;i<g.vn;i++) if(res[i])
        {
            if(!order[i]&&res[i]>1)
            {
                printf("  SPF node %d leaves %d subnets\n",i+1,res[i]);
                empty=false;
            }
            else if(order[i])
            {
                printf("  SPF node %d leaves %d subnets\n",i+1,res[i]+1);
                empty=false;
            }
        }
        if(empty) printf("  No SPF nodes\n");
	    cout<<endl;
    }
};

int main()
{
    int from,to;
	int flag=1;
	Graph g;
	Tarjan ft;
    g.init(1000);
	for(int ca=1;cin>>from;)
	{
		if(!from)
		{
			if(flag)break;
			printf("Network #%d\n",ca);
			ft.init(g);
			ft.go();
			ft.printRes();
			flag=1;
            g.init(1000);
			ca++;
		}
		else
		{
			flag=0;
			cin>>to;
			g.addEdge(from-1,to-1);
			g.addEdge(to-1,from-1);
		}
	}

    return 0;
}
